/*
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */

@isTest
private class ctrl_PackageSelection_Test
{
    static testMethod void testRunMethod()
    {
        // TO DO: implement unit test
        string result = null;
        PageReference pageRef = null;
        Map<string,List<SelectOption>> tempMap  = null;
        
        Location__c locationObject1 = new Location__c();
        locationObject1.Name = 'Test Office';
        locationObject1.Location_Type__c = 'Office';
        locationObject1.Rental_Rate__c = 18000;
        insert locationObject1;
        
        //For Location Object Records...
        Location__c locationObject2 = new Location__c();
        locationObject2.Name = 'Test Land';
        locationObject2.Location_Type__c = 'Land';
        locationObject2.Rental_Rate__c = 18000;
        insert locationObject2;
        
        Location__c locationObject3 = new Location__c();
        locationObject3.Name = 'Test SM-Office';
        locationObject3.Location_Type__c = 'SM-Office';
        locationObject3.Rental_Rate__c = 18000;
        insert locationObject3;
        
        Location__c locationObject4 = new Location__c();
        locationObject4.Name = 'Test SM-Office1232';
        locationObject4.Location_Type__c = 'SM-Office';
        locationObject4.Rental_Rate__c = 18000;
        insert locationObject4;
        
        //Account Object Record...
        Account accountObject = new Account();
        accountObject.Name = 'Test Account';
        //accountObject.LicenseNumber__c = serialObject.id;
        accountObject.License_Application_Step__c = 'Record Created';
        accountObject.License_Application_Type__c = 'New License';
        accountObject.Activity__c = 'Trading - One Activity';
        accountObject.License_Issue_Date__c = system.today();
        accountObject.License_Expiry_Date__c = System.Today().addYears(1);
        accountObject.Master_Account_Flag__c = true;
        
        insert accountObject;
        
          //For Location booking Objects Records...
        Location_Booking_Information__c locationBookingObject1 = new Location_Booking_Information__c();
        locationBookingObject1.Account__c = accountObject.id;
        locationBookingObject1.Location__c = locationObject1.Id;
        locationBookingObject1.License_Booking_Status__c = 'Booked';
        insert locationBookingObject1;
        
        Location_Booking_Information__c locationBookingObject2 = new Location_Booking_Information__c();
        locationBookingObject2.Account__c = accountObject.id;
        locationBookingObject2.Location__c = locationObject2.Id;
        locationBookingObject2.License_Booking_Status__c = 'Booked';
        insert locationBookingObject2;
        
        //For Tenancy Object Records...
        RecordType recordType = [select Id,IsActive,SObjectType,DeveloperName from RecordType where DeveloperName = 'New_Tenancy_Contract' AND SObjectType = 'Tenancy_Contract__c'];
        Tenancy_Contract__c tenancyObject = new Tenancy_Contract__c();
        tenancyObject.Location__c = locationObject2.id;
        tenancyObject.RecordTypeId = recordType.id;
        tenancyObject.Tenant__c = accountObject.id;
        tenancyObject.Tenancy_Contract_Start_Date__c = accountObject.License_Issue_Date__c;
        tenancyObject.Tenancy_Contract_Expiry_Date__c = date.TODAY().addyears(1).adddays(-1);
        insert tenancyObject;
        
        Map<string,RecordType> amendmentRecordTypeMap = new Map<string,RecordType>();
        for(RecordType tempObject : [SELECT Id,SObjectType,DeveloperName,IsActive FROM RecordType where SObjectType =: 'Amendment__c' AND IsActive =: true])
        {
            amendmentRecordTypeMap.put(tempObject.DeveloperName, tempObject);
            
        }
        
        //For Amendment Object For Company Name...
        Amendment__c amendmentObject1 = new Amendment__c();
        amendmentObject1.RecordTypeId = amendmentRecordTypeMap.get('Location_Amendment_Add_Location').Id;
        amendmentObject1.Account__c = accountObject.Id;
        amendmentObject1.New_Location__c = locationObject1.Id;
        amendmentObject1.New_Location_2__c = locationObject2.Id;
        amendmentObject1.New_Location_3__c = locationObject3.Id;
        insert amendmentObject1;
        
        //Now For Account Locations ....
        Account_Location__c accountLocationObject1 = new Account_Location__c();
        accountLocationObject1.Account__c = accountObject.Id;
        accountLocationObject1.Previous_Location__c = locationObject1.Id;
        accountLocationObject1.Previous_Tenancy_Contract__c = tenancyObject.Id;
        insert accountLocationObject1;
        
        Account_Location__c accountLocationObject2 = new Account_Location__c();
        accountLocationObject2.Account__c = accountObject.Id;
        accountLocationObject2.New_Location__c = locationObject4.Id;
        insert accountLocationObject2;
        
        
        //For Payment Plans...
        List<Payment_Plan__c> paymentList = new List<Payment_Plan__c>();
        
        Payment_Plan__c paymentObject1 = new Payment_Plan__c();
        paymentObject1.Action__c = 'Discount';
        paymentObject1.Installment__c = '1';
        paymentObject1.Percent__c = 10;
        paymentObject1.isActive__c = true;
        paymentObject1.License_Application_Type__c = 'New License';
        paymentObject1.Location_Type__c = 'Office';
        //Adding in the List...
        paymentList.add(paymentObject1);
        
        Payment_Plan__c paymentObject2 = new Payment_Plan__c();
        paymentObject2.Action__c = 'Discount';
        paymentObject2.Installment__c = '1';
        paymentObject2.Percent__c = 10;
        paymentObject2.isActive__c = true;
        paymentObject2.License_Application_Type__c = 'New License';
        paymentObject2.Location_Type__c = 'Land';
        //Adding in the List...
        paymentList.add(paymentObject2);
        
        Payment_Plan__c paymentObject3 = new Payment_Plan__c();
        paymentObject3.Action__c = 'Discount';
        paymentObject3.Installment__c = '1';
        paymentObject3.Percent__c = 10;
        paymentObject3.isActive__c = true;
        paymentObject3.License_Application_Type__c = 'New License';
        paymentObject3.Location_Type__c = 'SM-Office';
        //Adding in the List...
        paymentList.add(paymentObject3);
        
        
        Payment_Plan__c paymentObject4 = new Payment_Plan__c();
        paymentObject4.Action__c = 'Discount';
        paymentObject4.Installment__c = '1';
        paymentObject4.Percent__c = 10;
        paymentObject4.isActive__c = true;
        paymentObject4.License_Application_Type__c = 'Renewal';
        paymentObject4.Location_Type__c = 'Office';
        //Adding in the List...
        paymentList.add(paymentObject4);
        
        Payment_Plan__c paymentObject5 = new Payment_Plan__c();
        paymentObject5.Action__c = 'Discount';
        paymentObject5.Installment__c = '1';
        paymentObject5.Percent__c = 10;
        paymentObject5.isActive__c = true;
        paymentObject5.License_Application_Type__c = 'Renewal';
        paymentObject5.Location_Type__c = 'Land';
        //Adding in the List...
        paymentList.add(paymentObject5);
        
        Payment_Plan__c paymentObject6 = new Payment_Plan__c();
        paymentObject6.Action__c = 'Discount';
        paymentObject6.Installment__c = '1';
        paymentObject6.Percent__c = 10;
        paymentObject6.isActive__c = true;
        paymentObject6.License_Application_Type__c = 'Renewal';
        paymentObject6.Location_Type__c = 'SM-Office';
        //Adding in the List...
        paymentList.add(paymentObject6);
        
        
        Payment_Plan__c paymentObject7 = new Payment_Plan__c();
        paymentObject7.Action__c = 'Discount';
        paymentObject7.Installment__c = '1';
        paymentObject7.Percent__c = 10;
        paymentObject7.isActive__c = true;
        paymentObject7.License_Application_Type__c = 'Renewal Amendment';
        paymentObject7.Location_Type__c = 'Office';
        //Adding in the List...
        paymentList.add(paymentObject7);
        
        Payment_Plan__c paymentObject8 = new Payment_Plan__c();
        paymentObject8.Action__c = 'Discount';
        paymentObject8.Installment__c = '1';
        paymentObject8.Percent__c = 10;
        paymentObject8.isActive__c = true;
        paymentObject8.License_Application_Type__c = 'Renewal Amendment';
        paymentObject8.Location_Type__c = 'Land';
        //Adding in the List...
        paymentList.add(paymentObject8);
        
        Payment_Plan__c paymentObject9 = new Payment_Plan__c();
        paymentObject9.Action__c = 'Discount';
        paymentObject9.Installment__c = '1';
        paymentObject9.Percent__c = 10;
        paymentObject9.isActive__c = true;
        paymentObject9.License_Application_Type__c = 'Renewal Amendment';
        paymentObject9.Location_Type__c = 'SM-Office';
        //Adding in the List...
        paymentList.add(paymentObject9);
        
        Payment_Plan__c paymentObject10 = new Payment_Plan__c();
        paymentObject10.Action__c = 'Discount';
        paymentObject10.Installment__c = '1';
        paymentObject10.Percent__c = 10;
        paymentObject10.isActive__c = true;
        paymentObject10.License_Application_Type__c = 'Amendment';
        paymentObject10.Location_Type__c = 'Office';
        //Adding in the List...
        paymentList.add(paymentObject10);
        
        Payment_Plan__c paymentObject11 = new Payment_Plan__c();
        paymentObject11.Action__c = 'Discount';
        paymentObject11.Installment__c = '1';
        paymentObject11.Percent__c = 10;
        paymentObject11.isActive__c = true;
        paymentObject11.License_Application_Type__c = 'Amendment';
        paymentObject11.Location_Type__c = 'Land';
        //Adding in the List...
        paymentList.add(paymentObject11);
        
        Payment_Plan__c paymentObject12 = new Payment_Plan__c();
        paymentObject12.Action__c = 'Discount';
        paymentObject12.Installment__c = '1';
        paymentObject12.Percent__c = 10;
        paymentObject12.isActive__c = true;
        paymentObject12.License_Application_Type__c = 'Amendment';
        paymentObject12.Location_Type__c = 'SM-Office';
        //Adding in the List...
        paymentList.add(paymentObject12);
        
        
        //Inserting the List...
        insert paymentList;
        
        /******************* Now Calling the Package Class Method **********************************/
        ApexPages.StandardController paymentPlanExtendedObject1 = new ApexPages.StandardController(paymentList[0]);
 
        ApexPages.CurrentPage().getParameters().put('licenseType','Renewal');
        ApexPages.CurrentPage().getParameters().put('isPerformaInvoice','True');
        ApexPages.CurrentPage().getParameters().put('tenancyID',tenancyObject.Id);       
        
        
        ctrl_PackageSelection packageSelectionClass1 = new ctrl_PackageSelection(paymentPlanExtendedObject1);
        pageRef = packageSelectionClass1.cancelButton();
        pageRef = packageSelectionClass1.loadingPaymentPlanMethod();
        tempMap = packageSelectionClass1.getInstallment();
        pageRef = packageSelectionClass1.displayMessagePanel();
        pageRef = packageSelectionClass1.generateInvoiceMethod();

        
        ApexPages.CurrentPage().getParameters().put('licenseType','Renewal');
        ApexPages.CurrentPage().getParameters().put('isPerformaInvoice','True');
        ApexPages.CurrentPage().getParameters().put('accountID',accountObject.Id);  
        ApexPages.CurrentPage().getParameters().put('tenancyID',null);
        //ApexPages.CurrentPage().getParameters().put('amendmentID',amendmentObject1.Id);
        
        //Now Change the License Type...    
        ApexPages.StandardController paymentPlanExtendedObject2 = new ApexPages.StandardController(paymentList[1]);
        ctrl_PackageSelection packageSelectionClass2 = new ctrl_PackageSelection(paymentPlanExtendedObject2);
        pageRef = packageSelectionClass2.loadingPaymentPlanMethod();
        tempMap = packageSelectionClass2.getInstallment();
        pageRef = packageSelectionClass2.generateInvoiceMethod();
        
        
        ApexPages.CurrentPage().getParameters().put('licenseType','New License');
        ApexPages.CurrentPage().getParameters().put('isPerformaInvoice','True');
        ApexPages.CurrentPage().getParameters().put('accountID',accountObject.Id);  
        
        //Now Change the License Type...    
        ApexPages.StandardController paymentPlanExtendedObject3 = new ApexPages.StandardController(paymentList[2]);
        ctrl_PackageSelection packageSelectionClass3 = new ctrl_PackageSelection(paymentPlanExtendedObject3);
        pageRef = packageSelectionClass3.loadingPaymentPlanMethod();
        tempMap = packageSelectionClass3.getInstallment();
        pageRef = packageSelectionClass3.generateInvoiceMethod();
        
        
        ApexPages.CurrentPage().getParameters().put('licenseType','Amendment');
        ApexPages.CurrentPage().getParameters().put('isPerformaInvoice','True');
        ApexPages.CurrentPage().getParameters().put('accountID',null);
        ApexPages.CurrentPage().getParameters().put('amendmentID',amendmentObject1.Id);  
        
        //Now Change the License Type...    
        ApexPages.StandardController paymentPlanExtendedObject4 = new ApexPages.StandardController(paymentList[3]);
        ctrl_PackageSelection packageSelectionClass4 = new ctrl_PackageSelection(paymentPlanExtendedObject4);
        pageRef = packageSelectionClass4.loadingPaymentPlanMethod();
        tempMap = packageSelectionClass4.getInstallment();
        pageRef = packageSelectionClass4.generateInvoiceMethod();
        
        ApexPages.CurrentPage().getParameters().put('licenseType','Renewal Amendment');
        ApexPages.CurrentPage().getParameters().put('isPerformaInvoice','True');
        ApexPages.CurrentPage().getParameters().put('accountID',accountObject.Id);
        ApexPages.CurrentPage().getParameters().put('amendmentID',null);  
        
        //Now Change the License Type...    
        ApexPages.StandardController paymentPlanExtendedObject5 = new ApexPages.StandardController(paymentList[4]);
        ctrl_PackageSelection packageSelectionClass5 = new ctrl_PackageSelection(paymentPlanExtendedObject5);
        pageRef = packageSelectionClass5.loadingPaymentPlanMethod();
        tempMap = packageSelectionClass5.getInstallment();
        pageRef = packageSelectionClass5.generateInvoiceMethod();
    
    }
                   
    
}